<template>
  <div class="login">
    <!-- 添加一个登录表单 -->
    <el-form class="myform" :model="form" :rules="rules">
      <h3 class="title">iHRM后台登录系统</h3>
      <!-- 表单域 -->
      <el-form-item prop="mobile">
        <el-input
          v-model="form.mobile"
          placeholder="mobile"
          prefix-icon="el-icon-user-solid"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="form.password"
          type="password"
          placeholder="password"
          prefix-icon="el-icon-lock"
          show-password
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="mybtn" type="primary">登录</el-button>
      </el-form-item>
      <el-form-item>
        <div class="txt">还没有账号？立即注册</div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      form: {
        mobile: "13800000002",
        password: "123456",
      },
      rules: {
        mobile: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              // 校验手机号的合法
              // 1.0 定义一个手机号的正则
              const reg =
                /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
              // 2.0 用正则去匹配 value
              const bool = reg.test(value);

              // 3.0 返回 true ，说明通过，否则，提示错误
              bool ? callback() : callback(new Error("手机号不合法"));
            },
            trigger: "blur",
          },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
};
</script>

<style lang="scss">
.login {
  height: 100%;
  background-image: url("../../assets/common/login.jpg");
  background-position: center;
  position: relative;
  .myform {
    position: absolute;
    width: 450px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -66%);

    .title {
      color: #fff;
      font-size: 50px;
      font-weight: 400;
    }
    input.el-input__inner {
      color: #68b0fe;
      background-color: #d4e4ff;
    }
    .el-form-item__error {
      color: #fff;
    }

    .mybtn {
      width: 100%;
      height: 64px;
      background-color: #407ffe;
      color: #fff;
      font-size: 24px;
    }
    .txt {
      text-align: center;
      color: #fff;
    }
  }
}
</style>